<?php

function CreateSessionId()
{
    $chars = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    $sessionid = "";
    for($idx = 0;$idx < 20;$idx++) {
        $random_number = rand(0,strlen($chars)-1);
        $sessionid = $sessionid . $chars[$random_number];
    }
    return $sessionid;
}


function GetUserFromSession($sessionid)
{
    $userid = 0;
    $subquery = "SELECT userid FROM sessionlist WHERE MD5(sessionid) = '$sessionid' AND sessiontime > DATE_SUB(NOW(),INTERVAL 3 HOUR)";
    $subresult = mysql_query($subquery);

    if ($subresult && ($row = mysql_fetch_array($subresult)))
    {
        list($userid) = $row;
    }
    return $userid;
}




?>